/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ga.coordination;

/**
 *
 * @author hartono
 */
public class Factory {    
         
    public World world;
    /**
     * Dana / modal pabrik ($)
     */
    public long fund;
    
    /**
     * Jam kerja maksimum pabrik (H)
     */
    public byte hour;
    
    /**
     * Jumlah maksimum jenis mesin yang bisa disewa (N)
     */
    public byte totalMachine;
        
    /**
     * Jumlah mesin yang disewa
     */
    public byte nRentMachine;
    
    /**
     * List dari mesin yang disewa pabrik
     */
    public byte idMachineList [];
    
    /**
     * Posisi pabrik di peta dengan absis xPosition
     */
    public byte xPosition;
    
    /**
     * Posisi pabrik di peta dengan ordinat yPosition
     */
    public byte yPosition;
    
    /**
     * Jam mulai operasi pabrik
     */
    public byte startTime;
    
    /**
     * Hari operasi pabrik tersebut
     */
    public String day;

    
    /**
     * Default Constructor
     */
    public Factory(World world) {
        this.world = world;
        day = "Selasa";
        startTime = 0;                
    }

    public Factory(byte fund, byte hour, byte totalMachine, byte[] idMachineList, byte xPosition, byte yPosition, byte startTime, String day) {
        this.fund = fund;
        this.hour = hour;
        this.totalMachine = totalMachine;
        this.idMachineList = idMachineList;
        this.xPosition = xPosition;
        this.yPosition = yPosition;
        this.startTime = startTime;
        this.day = day;
    }
    
    
    
    /**
     * Copy Constructor
     * @param f 
     */
    public Factory (Factory f){
        this.day = f.day;
        this.fund = f.fund;
        this.hour = f.hour;
        this.idMachineList = f.idMachineList;
        this.startTime = f.startTime;
        this.totalMachine = f.totalMachine;
        this.xPosition = f.xPosition;
        this.yPosition = f.yPosition;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        if (nRentMachine!=0){
            for (int i=0;i< nRentMachine;i++){
                sb.append(idMachineList[i]);
                sb.append(' ');
            }    
        }else{
            sb.append('-');
        }               
        return "Factory ("+ xPosition+","+yPosition +") fund:" +fund+" totalMachineCapacity:"+totalMachine + " Mesin yang disewa: " +sb;
    }
    
    
    
    /**
     * Akan mengecek apakah dana / modal / fund cukup untuk menyewa
     * mesin dengan idMachine 
     * @param idMachine 
     * @return 
     * 
     */
    public boolean IsFundSufficient(byte idMachine){
        try{
            int harga = world.machineList[idMachine].rentCost;
            return (fund - harga)>=0;
        }catch (Exception e){
            return false;    
        }                
    }
    
    /**
     * Akan mengurangi uang pabrik bila menyewa mesin dengan idMachine
     * @param idMachine 
     */
    public void ReduceFund(byte idMachine){
        try{
            int harga = world.machineList[idMachine].rentCost;
            if ((fund-harga)>=0){
                fund -= harga;
            }
        }catch(Exception e){
            
        }
    }
    
        
}
